﻿
Partial Class WebForm_SearchControl_SearchVolunteerControl
    Inherits System.Web.UI.UserControl

    Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
        If e.CommandName = "Select" Then
            'dim row as GridViewRow trycast(e.CommandSource,Control).NamingContainer,GridViewRow
            Dim rowIndex As Integer = e.CommandArgument
            Me.SelectedVolunteerID = Me.gv.DataKeys(rowIndex)("VolunteerID")
            RaiseEvent SelectedIndexChanged(Me, New EventArgs)
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Visible = True
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
        Me.mpSearch.Show()
    End Sub
End Class

Partial Class WebForm_SearchControl_SearchVolunteerControl
    Public Sub Show()
        Me.BindGV()
        Me.mpSearch.Show()
    End Sub

    Private Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        If Me.UOrganizationID <> "" Then
            sql.Length = 0
            sql.AppendFormat("select v.* ")
            sql.AppendFormat(" from GetVolunteerByURoot('{0}') v ", Me.UOrganizationID)
            sql.AppendFormat("where Active = 'Y' ")

            sql.AppendFormat(Me.GetWhereSQL())

        Else
            sql.Length = 0
            sql.AppendFormat("select v.* ")
            sql.AppendFormat(" from VolunteerDistinctView v ")
            sql.AppendFormat("where Active = 'Y' ")

            sql.AppendFormat(Me.GetWhereSQL())

        End If

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()

    End Sub

    Public Function GetWhereSQL() As String
        Dim sql As New MyStringBuilder

        If Me.txtVolunteerName.Text <> "" Then
            sql.AppendFormat("and VolunteerName like '%{0}%' ", Me.txtVolunteerName.Text)
        End If

        Return sql.ToString()
    End Function

    Public Property SelectedVolunteerID() As String
        Get
            Return ViewState("SelectedVolunteerID")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedVolunteerID") = value
        End Set
    End Property

    Public Property UOrganizationID() As String
        Get
            Return ViewState("UOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("UOrganizationID") = value
        End Set
    End Property


    Public Event SelectedIndexChanged(ByVal source As Object, ByVal e As EventArgs)
End Class